package com.tleng;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

import com.tleng.GramAntlrParser.x_return;
import com.tleng.Nodos.NodoGenerico;



public class Test {
	public static void main(String[] args) throws IOException, RecognitionException{
		ANTLRInputStream input = new ANTLRInputStream(System.in);

        GramAntlrLexer lexer = new GramAntlrLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        GramAntlrParser parser = new GramAntlrParser(tokens);
        parser.setTreeAdaptor(new NuestroTreeAdaptor());
        
        x_return x = parser.x();

        NodoGenerico t = (NodoGenerico)x.getTree();
        
        t.SetearParametrosIniciales(0, 0, 1);
        t.calcularEscala();
        t.calcularAncho();
        t.calcularAlto();
        t.calcularX();
        t.calcularY();
        
        String res = t.Imprimir();
        
        String nombre = "";
        if(args.length != 0){
        	nombre = args[0];
        }else{
        	nombre = "res.ps";
        }
        FileWriter fstream = new FileWriter(nombre);
        BufferedWriter out = new BufferedWriter(fstream);
        
        out.write("%!PS-Adobe-3.0 EPSF-3.0\n");
        out.write("30 200 translate\n");
        out.write("50 50 scale\n");
        out.write(".03 setlinewidth\n");
        out.write("/Courier findfont setfont\n");
        out.write(res);
        out.write("showpage\n");
        out.close();

	}
}
